package com.smq.chatserver.controller;

import com.smq.chatserver.bean.Result;
import com.smq.chatserver.bean.message.ImMessage;
import com.smq.chatserver.bean.message.MessageQueryResult;
import com.smq.chatserver.services.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "消息模块")
@RestController
@RequestMapping("/message")
public class MessageController {


    @Autowired
    private MessageService messageService;

    @ApiOperation(value = "查询历史消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "beginTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "header"),
    })
    @PostMapping("/query")
    public Result<MessageQueryResult> query(Long beginTime, @RequestHeader String userId) {
        return messageService.query(userId, beginTime);
    }

    @ApiOperation(value = "发送消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "msgId", value = "消息唯一id", required = true),
            @ApiImplicitParam(name = "to", value = "接受方id", required = true),
            @ApiImplicitParam(name = "ope", value = "群聊/单聊", required = true),
            @ApiImplicitParam(name = "msg", value = "消息", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "header")
    })
    @PostMapping("/sendText")
    public Result<ImMessage> sendText(String msgId, String to, Integer ope, String msg, @RequestHeader String userId) {
        return messageService.sendText(msgId, to, ope, msg, userId);
    }
}
